import createG2 from 'g2-react';
import { Stat } from 'g2';
import React from 'react';
import ReactDOM from 'react-dom';
import Logger from '../../../../utils/Logger';

const logger = Logger.getLogger('LineChart');
 
const Line = createG2(chart => {   //线图
  chart.axis('count', {//设置x轴别名离轴的距离
     titleOffset: 50,
  });
  chart.col('count', {//为x轴设置别名
     alias:'统计',
  });

  chart.axis('timeStr', {//设置y轴别名离轴的距离
     titleOffset: 40
  });
  chart.col('timeStr', {//为y轴设置别名
     alias:'时间',
  });
  chart.line().position('timeStr*count').size(2);
  chart.render();
});

//声明一个数组，存放饼图数据

/**
 * 线型图
 */
class LineChart extends React.Component {

  constructor(props) {
    super(props);
    this.initLineData();
  }

  state = {
      width: 550,
      height: 450,
      plotCfg: {
        margin: [50, 100, 90, 120],
      },
      forceFit: true, //自适应
      data:[]
  };

  // 在react router中切换时, 组件不会重新mount, 只有props会变化
  componentWillReceiveProps = (nextProps) => {
    //this.initLineData();
  }

  initLineData(){
    //  if(!this.props.close){//没有闭馆
    //       this.setState({data:this.props.userData});
    //  }
  }

  render() {
    return (
      <div>
        <Line
          data={this.props.userData}
          width={this.state.width}
          height={this.state.height}
          plotCfg={this.state.plotCfg}
          forceFit={this.state.forceFit}
        />
      </div>
    );
  }
}
export default LineChart;